/**
 * @author zhanglongsheng
 * @since 2018.12.13
 */

function perOrder() {
    if (typeof WeixinJSBridge == "undefined"){
        if( document.addEventListener ){
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        }else if (document.attachEvent){
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    }else{
        onBridgeReady();
    }

    function onBridgeReady(){
        var jsapi =eval('(' + param + ')');
        WeixinJSBridge.invoke('getBrandWCPayRequest',jsapi,function(res){
                var result = "";
                var errMsg = "";
                if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                    result = "success";
                }else{
                    result = "error";
                    errMsg = "支付失败";
                }
            location.href = root + "pay/notice?ordNo=" + ordNo + "&result=" + result + "&errMsg=" + errMsg;
            }
        );
    }
}

$(function(){
    function onBridgeReady() {
        WeixinJSBridge.call('hideOptionMenu');
    }

    if (typeof WeixinJSBridge == "undefined") {
        if (document.addEventListener) {
            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
        } else if (document.attachEvent) {
            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
        }
    } else {
        onBridgeReady();
    }
});